import Date from '@/common/date.js'
export default {
	data () {
		return {
			form:{},
			phoneHeight: 0,
			dataList:[],
			tagList:[
				{title:'今天', shape:'square', mode:'dark', type:"primary", id:'T01'},
				{title:'昨天', shape:'square', mode:'dark', type:"info", id:'T02'},
				{title:'近七天', shape:'square', mode:'dark', type:"info", id:'T03'},
				{title:'近30天', shape:'square', mode:'dark', type:"info", id:'T04'}
			],
			rechargeList:[[
				{value:0,label:'全部',extra:0},
				{value:2,label:'充值',extra:1},
				{value:3,label:'消费',extra:2},
				{value:4,label:'次卡充值',extra:3},
				{value:5,label:'次卡消费',extra:4},
				{value:6,label:'购买服务',extra:5}
			]],
			searchForm:{
				shop_id: 0,
				shop_name:'全部',
			},
			billStatusList:[
				[
					{value:0,label:'全部',extra:0},
					{value:2,label:'盘点中',extra:1},
					{value:3,label:'已完成',extra:2},
				]
			]
		}
	},
	computed: {
		userInfo(){
			return this.$store.state.userInfo
		}
	},
	onReady() {
		this.searchForm.shop_id = this.userInfo.FStockID
		this.searchForm.shop_name = this.userInfo.FStockName
		uni.getSystemInfo({ 
			success: (res) => {
				let sHeight = 0
				uni.createSelectorQuery().select("#fobx").boundingClientRect((data) => {
					sHeight = data.height
				}).exec();
				uni.createSelectorQuery().select("#myscroll").boundingClientRect((data) => {
					this.phoneHeight = (res.windowHeight - data.top - sHeight)
				}).exec();
			}
		})
	},
	methods: {
		onTagBtn(ix){
			if(this.tagIndex === ix) return
			this.tagIndex = ix
			this.tagList = this.tagList.map((jm,jx)=>{
				if(ix === jx) {jm.type = 'primary'}
				else {
					jm.type = 'info'
				}
				return jm
			})
			switch(ix){
				case 0:
					this.dataList = []
					this.searchForm.page_index = 1
					this.searchForm.star_date = Date.getDate(0)
					this.searchForm.end_date = Date.getDate(0)
					this.init()
				break;
				case 1:
					this.dataList = []
					this.searchForm.page_index = 1	
					this.searchForm.star_date = Date.getDate(1)
					this.searchForm.end_date = Date.getDate(1)
					this.init()
				break;
				case 2:
					this.dataList = []
					this.searchForm.page_index = 1
					this.searchForm.star_date = Date.getDate(7)
					this.searchForm.end_date = Date.getDate(0)
					this.init()
				break;
				case 3:
					this.dataList = []
					this.searchForm.page_index = 1
					this.searchForm.star_date = Date.getDate(30)
					this.searchForm.end_date = Date.getDate(0)
					this.init()
				break;
			}
		},
		onClickChangeDate(arrDate){
			this.searchForm.star_date = arrDate[0]
			this.searchForm.end_date = arrDate[arrDate.length-1]
			this.form.star_date = arrDate[0]
			this.form.end_date = arrDate[arrDate.length-1]
		},
		// 信息类型(1商品分类,2会员分类,3供应商选择, 4会员等级, 5商品资料, 6会员资料, 7门店资料)
		getSelectItems(tp,listName, propName, index, showName){
			this.$reqGet(tp!==7?'SelectItems':'GetShopList',{
				type: tp,
				page_index: 1,
				page_size: 9999,
			}).then(res=>{
				if(tp !== 7){
					this[listName][0] = res.Data.map((im, ix)=>{
						return {label:im.FName, value:im.FItemID, extra:ix}
					})
				}else {
					this[listName][0] = res.Data.map((im, ix)=>{
						return {...im, label:im.FName, value:im.FStockID, extra:ix}
					})
				}
				this[showName] = true
				this[index] = this[listName][0].map(item=>item.value).indexOf(this.form[propName])
			})
		},
		// 搜索数据
		// upSearchDate(val){
		// 	this.form.name = val
		// 	this.init(val)
		// },
		hideIconBtn(){
			this.dataList = this.dataList.map((jm, jx) => {
				jm.isShow = false
				return jm
			})
		},
		onMoreActions(im, ix){
			this.dataList = this.dataList.map((jm, jx) => {
				if(ix != jx){
					jm.isShow = false
				}
				return jm
			})
			this.dataList[ix].isShow = true
		},
		confirmShop(e, value, name, index, list){
			if(e.indexs[0] == null || e.indexs[0] === -1){
				this[index]= 0
				this.searchForm[value] = this[list][this[index]][0].value
				this.searchForm[name] =this[list][this[index]][0].label
			}else {
				const uifo = this.$store.state.userInfo
				this.searchForm[value] = e.value[0].value
				this[index] = e.value[0].extra
				this.searchForm[name] = e.value[0].label
				const setUIfo = {
					...uifo,
					FStockName: e.value[0].label,
					shop_appid: e.value[0].shop_appid,
					FStockID: e.value[0].FStockID,
					FUserID: e.value[0].FUserID,
					FUserName: e.value[0].FTelephone
				}
				this.$store.commit('login', setUIfo)
			}
		}
	},
}